package com.cameron.serviceedu.controller;


import com.cameron.serviceedu.entity.EduVideo;
import com.cameron.serviceedu.service.EduVideoService;
import com.cameron.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author cameron
 * @since 2022-06-17
 */
@RestController
@RequestMapping("/service/edu-video")
@CrossOrigin
public class EduVideoController {

    @Resource
    private EduVideoService videoService;

    @PostMapping
    public Result add(@RequestBody EduVideo eduVideo) {
        return videoService.saveOrUpdate(eduVideo) ? Result.ok() : Result.error();
    }

    @DeleteMapping("{id}")
    public Result removeById(@PathVariable String id) {
        videoService.deleteById(id);
        return videoService.removeById(id) ? Result.ok() : Result.error();
    }

    @GetMapping("{id}")
    public Result getById(@PathVariable String id) {
        return Result.ok().data("subChapter", videoService.getById(id));
    }
}

